<?php 

class Controller{

	//Save the tpl virables
	protected $_tpl_data = array();
	protected $_layout = 'default';
	
	//Display the tpl
	protected function display($_tpl = null){
		
		$this->_tpl = $_tpl?$_tpl:PHPFun::$action;
		
		//the virables can't use in view
		unset($_tpl);
		
		$this->_tpl_path = APP_PATH.'/View/';
		$this->_tpl_path.= PHPFun::$controller.'/';
		$this->_tpl_path.= $this->_tpl.'.php';
		
		if(!file_exists($this->_tpl_path)){
		
			exit('tpl not exists');
		}
		
		extract($this->_tpl_data);
		
		ob_start();
		require($this->_tpl_path);
		$this->_tpl_content = ob_get_contents();
		ob_clean();
		
		$this->_master_path = APP_PATH.'/View/'.$this->_layout.'.php';
		require($this->_master_path);
		$this->_master_data = ob_get_contents();
		
		$this->_result = str_replace('{__CONTENT__}',$this->_tpl_content,$this->_master_data);
		ob_end_clean();

		echo $this->_result;
		
	}
	
	//Assign virables
	protected function assign($_arr){
	
		foreach($_arr as $_key=>$_value){
		
			$this->_tpl_data[$_key] = $_value;
		}
	}
}


?>